#include "sender.h"

#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QFile>
#include <QtGlobal>
#include <QDateTime>
#include <QStringList>

#include <iostream> //debug
using std::cout;
using std::endl;

namespace Tubox {

Sender::Sender(const QString &_serverUrl, const unsigned short _port) : serverUrl(QUrl(_serverUrl)), port(_port) {
	networkManager = new QNetworkAccessManager(this);
	connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SIGNAL(sigReply(QNetworkReply *)));
	this->serverUrl.setPort(port);	
}

Sender::~Sender(){
	delete networkManager;
}

void Sender::send(const QString &request) {
	cout << "sending: " << request.toStdString() << endl;
	networkManager->post(QNetworkRequest(serverUrl), request.toLatin1());
}

}
